using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using TerritoryGame.Infrastructure.Data;

namespace TerritoryGame.Infrastructure.Data.Migrations
{
    [DbContext(typeof(TerritoryGameDbContext))]
    [Migration("20250819000000_AddGameHistory")]
    public partial class AddGameHistory : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "GameHistories",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    RoomCode = table.Column<string>(type: "text", nullable: false),
                    RoomName = table.Column<string>(type: "text", nullable: false),
                    EndedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DurationSeconds = table.Column<int>(type: "integer", nullable: false),
                    WinnerPlayerId = table.Column<string>(type: "text", nullable: true),
                    WinnerNickname = table.Column<string>(type: "text", nullable: true),
                    WinnerColor = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GameHistories", x => x.Id);
                }
            );

            migrationBuilder.CreateTable(
                name: "GameHistoryPlayers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    GameHistoryId = table.Column<Guid>(type: "uuid", nullable: false),
                    PlayerId = table.Column<string>(type: "text", nullable: false),
                    Nickname = table.Column<string>(type: "text", nullable: false),
                    Color = table.Column<string>(type: "text", nullable: false),
                    Area = table.Column<double>(type: "double precision", nullable: false),
                    Rank = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GameHistoryPlayers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GameHistoryPlayers_GameHistories_GameHistoryId",
                        column: x => x.GameHistoryId,
                        principalTable: "GameHistories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                }
            );

            migrationBuilder.CreateIndex(
                name: "IX_GameHistoryPlayers_GameHistoryId",
                table: "GameHistoryPlayers",
                column: "GameHistoryId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "GameHistoryPlayers");
            migrationBuilder.DropTable(
                name: "GameHistories");
        }
    }
}


